package com.sihai.ehr.web.action.employee;

import com.sihai.core.LimitedList;
import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.*;
import com.sihai.ehr.model.biz.Transaction.TransactionType;
import com.sihai.ehr.model.sys.ExaminePeriodEnum;
import com.sihai.ehr.model.sys.Organization;
import com.sihai.ehr.service.DutyService;
import com.sihai.ehr.service.EmployeeService;
import com.sihai.ehr.service.ExamStatisticsService;
import com.sihai.ehr.service.GradeService;
import com.sihai.ehr.service.OrganizationService;
import com.sihai.ehr.service.SalaryAttendanceService;
import com.sihai.ehr.service.TransactionService;
import com.sihai.ehr.utils.DateUtil;
import com.sihai.ehr.utils.PeriodUtils;
import com.sihai.ehr.utils.StringUtil;
import com.sihai.ehr.web.action.EHRAction;
import com.sihai.ehr.web.action.ExportAction;
import com.sihai.ehr.web.pojo.EmployeeNoPojo;
import com.sihai.ehr.web.pojo.ExamStatisticsPojo;
import com.sihai.ehr.web.pojo.StaffSearchPojo;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Results({@Result(name = "list", location = "staff_list.jsp"),
        @Result(name = "seclist", location = "introducer_select.jsp"),
        @Result(name = "staffseclist", location = "staff_add_introducerSec.jsp"),
        @Result(name = "add", location = "staff_add.jsp"),
        @Result(name = "main", location = "staff_main.jsp"),
        @Result(name = "edit", location = "staff_edit.jsp"),
        @Result(name = "view", location = "staff_view.jsp"),
        @Result(name = "edu_list", location = "edu_list.jsp"),
        @Result(name = "train_list", location = "train_list.jsp"),
        @Result(name = "exp_list", location = "exp_list.jsp"),
        @Result(name = "family_list", location = "family_list.jsp"),
        @Result(name = "staff_attendance", location = "staff_attendance.jsp")	// added by henry
})
public class StaffAction extends ExportAction {

    @BeanInject
    private EmployeeService employeeService;
    @BeanInject
    private OrganizationService organizationService;
    @BeanInject
    private DutyService dutyService;
    @BeanInject
    private GradeService gradeService;
    //@ added by henry{
    @BeanInject
    private SalaryAttendanceService salaryAttendanceService;
    @BeanInject
    private ExamStatisticsService examStatisticsService;
    @BeanInject
    private TransactionService transactionService;
    //@}
    
    private EmployeeinfoBase employeeinfoBase;
    private EmployeeinfoWork employeeinfoWork;
    private EmployeeinfoEducation employeeinfoEducation;
    private EmployeeinfoTrain employeeinfoTrain;
    private EmployeeWorkExperience employeeWorkExperience;
    private EmployeeinfoFamily employeeinfoFamily;
    private List<Organization> childOrgs;
    private List<Organization> organizations;
    private List<Duty> duties;
    private List<Grade> grades;
    private List<Grade> gradeLvs;
    private Organization organization;
    private String employeeNo;
    private String empIds;
    private LimitedList<EmployeeinfoWork> employeeinfoWorks;
    private Long id;
    private List<EmployeeinfoEducation> employeeinfoEducationList;
    private List<EmployeeinfoTrain> employeeinfoTrains;
    private List<EmployeeWorkExperience> employeeWorkExperiences;
    private List<EmployeeinfoFamily> employeeinfoFamilies;
    // added by henry @{
    private LimitedList<Attendance> attendances;
    // @}
    //搜索对象
    private StaffSearchPojo search;
    //操作
    private String operation;
    //选择员工列表类型
    private String type;
    //职务ID
    private Long dutyId;
    //职级
    private Long gradeId;
    //职等
    private Long gradeLvId;

    private StaffSearchPojo pojo;

    private Long eduId;
    private Long orgParentId;
    private boolean topOrg;

    private boolean exportEmployee;

    private int startYear;
    private int endYear;
    private List<ExamPeriod> examPeriods;
    private LimitedList<ExamStatisticsPojo> examQuans;	//定量
    private LimitedList<ExamStatisticsPojo> examQuals;	//定性
    private LimitedList<ExamStatisticsPojo> examStats;	//全部
    private LimitedList<Transaction> orgTrans;	//部门异动
    private LimitedList<Transaction> proTrans;	//晋升异动
    private LimitedList<Transaction> demTrans;	//降职异动
    
    @Override
    @Action("/employee/staff")
    public String execute() throws Exception {
        listAction = String.format("/employee/staff_list.xhtml?operation=%s", operation);
        listTitle = "员工资料设置";

        organizations = organizationService.findChildren(null, true, null, null);
        if (organizations != null && organizations.size() > 0) {
        	if(getCurrentUserId() > 0){
            	Long topOrgId = getCurrentUser().getWork().getOrganization().getTopOrganization().getId();
            	Iterator<Organization> it = organizations.iterator();
            	while(it.hasNext()){
            		Organization o = it.next();
            		if(o.getId() != topOrgId){
            			it.remove();
            		}
            	}
            }
            organizationId = organizations.get(0).getId();
        }
        showChildOrg = true;
        exportEmployee = true;
        return "main";
    }

    @Action("/employee/staff_list")
    public String list() throws Exception {
        search = new StaffSearchPojo();
        search.setDepartment(organizationId);
        search.setDuty(dutyId);

        this.setSortProperty("id");
        this.setSortType("asc");
        employeeinfoWorks = employeeService.searchEmployeeinfoWorks(search, organizationId, "1", createLimit(), createSorter());
        //分页
        this.paging(employeeinfoWorks);
        //设置翻页action
        this.setPageUrl("employee/staff_list.xhtml");

        if (StringUtils.equals(operation, "select")) {
            return "seclist";
        } else if (StringUtils.equals(operation, "staffselect")) {
            return "staffseclist";
        }

        return "list";
    }

    //导出员工
    @Action(value = "/public/employee-report", results = {
            @Result(name = EXPORT_SUCCESS, type = "stream", params = {"contentType", "application/vnd.ms-excel", "contentDisposition", "attachment;fileName=\"${fileName}.xls\""})
    })
    public String report() throws Exception{
        search = new StaffSearchPojo();
        search.setDepartment(organizationId);
        search.setDuty(dutyId);

        this.setSortProperty("id");
        this.setSortType("asc");
        employeeinfoWorks = employeeService.searchEmployeeinfoWorks(search, organizationId, "1", null, null);

        return export(employeeinfoWorks);
    }

    @Action("/employee/staff_add")
    public String add() throws Exception {
        organizations = organizationService.findChildren(null, true, null, null);
        if(organizations != null && organizations.size() > 0 && getCurrentUserId() > 0){
        	Long topOrgId = getCurrentUser().getWork().getOrganization().getTopOrganization().getId();
        	Iterator<Organization> it = organizations.iterator();
        	while(it.hasNext()){
        		Organization o = it.next();
        		if(o.getId() != topOrgId){
        			it.remove();
        		}
        	}
        }
        long start = System.currentTimeMillis();
        ServletActionContext.getRequest().getSession().setAttribute("startTime", start); //设置开始时间
        return "add";
    }

    @Action(value = "/employee/staff_edit")
    public String edit() throws Exception {
        employeeinfoWork = employeeService.getEmployeeinfoWork(id);
        Organization org = employeeinfoWork.getOrganization().getTopOrganization();
        if (org != null) {
            orgParentId = org.getId();
            topOrg = true;
        }else{
            orgParentId=employeeinfoWork.getOrganization().getId();
        }
        organizations = organizationService.findChildren(null, true,
                null, null);


        employeeinfoEducationList = employeeService.getEducationList(employeeinfoWork.getBaseId(), null, null);
        employeeinfoTrains = employeeService.getTrainList(employeeinfoWork.getBaseId(), null, null);
        employeeWorkExperiences = employeeService.getWorkExperienceList(employeeinfoWork.getBaseId(), null, null);
        employeeinfoFamilies = employeeService.getEmployeeFamilyList(employeeinfoWork.getBaseId(), null, null);

        long start = System.currentTimeMillis();
        ServletActionContext.getRequest().getSession().setAttribute("startTime", start); //设置开始时间
        return "edit";
    }
    
    @Action("/employee/staff_view")
    public String view() throws Exception {
        employeeinfoWork = employeeService.getEmployeeinfoWork(id);
        employeeinfoEducationList = employeeService.getEducationList(employeeinfoWork.getBaseId(), null, null);
        employeeinfoTrains = employeeService.getTrainList(employeeinfoWork.getBaseId(), null, null);
        employeeWorkExperiences = employeeService.getWorkExperienceList(employeeinfoWork.getBaseId(), null, null);
        employeeinfoFamilies = employeeService.getEmployeeFamilyList(employeeinfoWork.getBaseId(), null, null);

        try{
            startYear = NumberUtils.createInteger(PropertiesLoaderUtils.loadAllProperties("jdbc.properties").getProperty("attendance_start_year", "2001"));
        }catch (Exception e){
            startYear = 2001;
        }
        endYear = Calendar.getInstance().get(Calendar.YEAR);
        
        //读取考核
        Calendar mCalendar = Calendar.getInstance();
        examPeriods = PeriodUtils.getLateThreeExamPeriodTOReverse(ExaminePeriodEnum.monthly, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH) + 1);
        if (examPeriods != null) {
        	examQuans = examStatisticsService.searchExamStatisticsPojoForUser(2, id, ExaminePeriodEnum.monthly, examPeriods);
        	examQuals = examStatisticsService.searchExamStatisticsPojoForUser(1, id, ExaminePeriodEnum.monthly, examPeriods);
        	examStats = examStatisticsService.searchExamStatisticsPojoForUser(0, id, ExaminePeriodEnum.monthly, examPeriods);
        }
        //
        orgTrans = transactionService.findTransactionByWorkIdAndType(id, TransactionType.organization, null, null, null);
        proTrans = transactionService.findTransactionByWorkIdAndType(id, TransactionType.promotion, null, null, null);
        demTrans = transactionService.findTransactionByWorkIdAndType(id, TransactionType.demotion, null, null, null);
        
        return "view";
    }
    //salaryAttendanceService
    @Action("/employee/staff_attendance")
    public String viewStaffAttendance() throws Exception{
    	Long workId = getParameter("workId") == null ? -1 : Long.parseLong(getParameter("workId").toString());
    	String attendStartDate = getParameter("attendStartDate") == null ? "" : getParameter("attendStartDate").toString();
    	String attendEndDate = getParameter("attendEndDate") == null ? "" : getParameter("attendEndDate").toString();
    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    	Date mStartDate = attendStartDate.isEmpty() ? null : formatter.parse(attendStartDate);
    	Date mEndDate = attendEndDate.isEmpty() ? null : formatter.parse(attendEndDate);
    	
    	attendances = salaryAttendanceService.findAttendancesByWorkId(workId, mStartDate == null ? -1 : mStartDate.getYear(), mStartDate == null ? -1 : mStartDate.getMonth(), 
    			mEndDate == null ? -1 : mEndDate.getYear(), mEndDate == null ? -1 : mEndDate.getMonth(), createLimit(), createSorter());
    	setPageUrl("employee/staff_attendance.xhtml");
        paging(attendances);
        return "staff_attendance";
    }

    @Action(value = "/employee/staff_create", results = {
            @Result(name = "success", type = "json")
    })
    public String create() throws Exception {

        if (employeeinfoBase != null && employeeinfoBase.getId() != null) {
            EmployeeinfoBase base = employeeService.getEmployeeinfoBase(employeeinfoBase.getId());
            base.setName(employeeinfoBase.getName());
            base.setAddress(employeeinfoBase.getAddress());
            base.setArchives(employeeinfoBase.getArchives());
            base.setAvoirdupois(employeeinfoBase.getAvoirdupois());
            base.setBaby(employeeinfoBase.getBaby());
            base.setBirthday(employeeinfoBase.getBirthday());
            base.setCensus(employeeinfoBase.getCensus());
            base.setCertificate(employeeinfoBase.getCertificate());
            base.setCompensation(employeeinfoBase.getCompensation());
            base.setEmail(employeeinfoBase.getEmail());
            base.setEnglishDialog(employeeinfoBase.getEnglishDialog());
            base.setEnglishLetter(employeeinfoBase.getEnglishLetter());
            base.setEnglishRead(employeeinfoBase.getEnglishRead());
            base.setEnglishWrite(employeeinfoBase.getEnglishWrite());
            base.setEntryDate(employeeinfoBase.getEntryDate());
            base.setEyeLeft(employeeinfoBase.getEyeLeft());
            base.setEyeRight(employeeinfoBase.getEyeRight());
            base.setLanguageDialog(employeeinfoBase.getLanguageDialog());
            base.setLanguageLetter(employeeinfoBase.getLanguageLetter());
            base.setLanguageRead(employeeinfoBase.getLanguageRead());
            base.setLanguageWrite(employeeinfoBase.getLanguageWrite());
            base.setFacePath(employeeinfoBase.getFacePath());
            base.setRemark(employeeinfoBase.getRemark());
            base.setPostcode(employeeinfoBase.getPostcode());
            base.setSchool(employeeinfoBase.getSchool());
            base.setSex(employeeinfoBase.getSex());
            base.setStature(employeeinfoBase.getStature());
            base.setTech(employeeinfoBase.getTech());
            base.setTel(employeeinfoBase.getTel());
            base.setHandSet(employeeinfoBase.getHandSet());
            base.setMarry(employeeinfoBase.getMarry());
            base.setFolk(employeeinfoBase.getFolk());
            base.setSalaryNo(employeeinfoBase.getSalaryNo());
            employeeService.updateEmployeeRelatedEntity(base);
        } else {
            employeeinfoBase.setState("1");
            employeeinfoBase.setCancel("0");
            employeeService.saveEmployeeBase(employeeinfoBase);
        }


        if (employeeinfoWork.getId() != null) {
            EmployeeinfoWork work = employeeService.getEmployeeinfoWork(employeeinfoWork.getId());
            work.setDuty(employeeinfoWork.getDuty());
            work.setOrganization(employeeinfoWork.getOrganization());
            work.setGrade(employeeinfoWork.getGrade());
            work.setGradeLevel(employeeinfoWork.getGradeLevel());
            work.setIntroducer(employeeinfoWork.getIntroducer());
            employeeService.updateEmployeeRelatedEntity(work);
        } else {
            employeeinfoWork.setBaseId(employeeinfoBase);
            employeeinfoWork.setDismission("0");
            employeeinfoWork.setCancel("0");
            employeeService.saveEmployeeinfoWork(employeeinfoWork);
        }

        ServletActionContext.getRequest().getSession().setAttribute("baseinfo", employeeinfoBase);
        return SUCCESS;
    }

    @Action(value = "/employee/staff_education", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoEducationList"})
    })
    public String education() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoEducation.setBaseId(employeeinfoBase);
        employeeinfoEducation.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoEducation.getBeginDate(), employeeinfoEducation.getEndDate()));
        employeeService.saveEducation(employeeinfoEducation);
        List<EmployeeinfoEducation> edus = employeeService.getEducationList(employeeinfoBase, null, null);
        employeeinfoEducationList = new ArrayList<EmployeeinfoEducation>();
        for (EmployeeinfoEducation edu : edus) {
            edu.setBeginDateStr(DateUtil.getStrByDate(edu.getBeginDate(), "yyyy年MM月"));
            edu.setEndDateStr(DateUtil.getStrByDate(edu.getEndDate(), "yyyy年MM月"));
            employeeinfoEducationList.add(edu);
        }
        return SUCCESS;
    }

    @Action(value = "/employee/edu_list", results = {
            @Result(name = "success", type = "json")
    })
    public String education_list() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoEducation.setBaseId(employeeinfoBase);
        employeeinfoEducation.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoEducation.getBeginDate(), employeeinfoEducation.getEndDate()));
        if (employeeinfoEducation.getId() == null) {
            employeeService.saveEducation(employeeinfoEducation);
        } else {
            employeeService.updateEmployeeRelatedEntity(employeeinfoEducation);
        }

        List<EmployeeinfoEducation> edus = employeeService.getEducationList(employeeinfoBase, null, null);
        if(edus != null && !edus.isEmpty()){
            employeeinfoEducationList = new ArrayList<EmployeeinfoEducation>();
            for (EmployeeinfoEducation edu : edus) {
                edu.setBeginDateStr(DateUtil.getStrByDate(edu.getBeginDate(), "yyyy年MM月"));
                edu.setEndDateStr(DateUtil.getStrByDate(edu.getEndDate(), "yyyy年MM月"));
                employeeinfoEducationList.add(edu);
            }
        }
        return "edu_list";
    }

    @Action(value = "/employee/getEduinfoById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoEducation"})
    })
    public String modify_education() throws Exception {

        employeeinfoEducation = employeeService.getEmployeeinfoEducationById(eduId);
        if (employeeinfoEducation != null) {
            employeeinfoEducation.setBeginDateStr(DateUtil.getStrByDate(employeeinfoEducation.getBeginDate(), "yyyy-MM-dd"));
            employeeinfoEducation.setEndDateStr(DateUtil.getStrByDate(employeeinfoEducation.getEndDate(), "yyyy-MM-dd"));
        }
        return SUCCESS;
    }

    @Action(value = "/employee/getTrainfoById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoTrain"})
    })
    public String modify_train() throws Exception {
        employeeinfoTrain = employeeService.getEmployeeinfoTrainById(eduId);
        if (employeeinfoTrain != null) {
            employeeinfoTrain.setBeginDateStr(DateUtil.getStrByDate(employeeinfoTrain.getBeginDate(), "yyyy-MM-dd"));
            employeeinfoTrain.setEndDateStr(DateUtil.getStrByDate(employeeinfoTrain.getEndDate(), "yyyy-MM-dd"));
        }
        return SUCCESS;
    }

    @Action(value = "/employee/getExperienceById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeWorkExperience"})
    })
    public String modify_experience() throws Exception {

        employeeWorkExperience = employeeService.getEmployeeWorkExperienceById(eduId);
        if (employeeWorkExperience != null) {
            employeeWorkExperience.setBeginDateStr(DateUtil.getStrByDate(employeeWorkExperience.getBeginDate(), "yyyy-MM-dd"));
            employeeWorkExperience.setEndDateStr(DateUtil.getStrByDate(employeeWorkExperience.getEndDate(), "yyyy-MM-dd"));
        }
        return SUCCESS;
    }

    @Action(value = "/employee/getFamilyById", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoFamily"})
    })
    public String modify_family() throws Exception {

        employeeinfoFamily = employeeService.getEmployeeFamilyById(eduId);

        return SUCCESS;
    }

    @Action(value = "/employee/staff_train", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeinfoTrains"})
    })
    public String train() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoTrain.setBaseId(employeeinfoBase);
        employeeinfoTrain.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoTrain.getBeginDate(), employeeinfoTrain.getEndDate()));
        employeeService.saveEmployeeTrain(employeeinfoTrain);

        List<EmployeeinfoTrain> trains = employeeService.getTrainList(employeeinfoBase, null, null);
        employeeinfoTrains = new ArrayList<EmployeeinfoTrain>();
        for (EmployeeinfoTrain train : trains) {
            train.setBeginDateStr(DateUtil.getStrByDate(train.getBeginDate(), "yyyy年MM月"));
            train.setEndDateStr(DateUtil.getStrByDate(train.getEndDate(), "yyyy年MM月"));
            employeeinfoTrains.add(train);
        }
        return SUCCESS;
    }

    @Action(value = "/employee/train_list")
    public String train_list() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoTrain.setBaseId(employeeinfoBase);
        employeeinfoTrain.setDiffMon(DateUtil.getMonthsOfAge(employeeinfoTrain.getBeginDate(), employeeinfoTrain.getEndDate()));
        if (employeeinfoTrain.getId() == null) {
            employeeService.saveEmployeeTrain(employeeinfoTrain);
        } else {
            employeeService.updateEmployeeRelatedEntity(employeeinfoTrain);
        }

        List<EmployeeinfoTrain> trains = employeeService.getTrainList(employeeinfoBase, null, null);
        employeeinfoTrains = new ArrayList<EmployeeinfoTrain>();
        for (EmployeeinfoTrain train : trains) {
            train.setBeginDateStr(DateUtil.getStrByDate(train.getBeginDate(), "yyyy年MM月"));
            train.setEndDateStr(DateUtil.getStrByDate(train.getEndDate(), "yyyy年MM月"));
            employeeinfoTrains.add(train);
        }
        return "train_list";
    }

    @Action(value = "/employee/staff_exp", results = {
            @Result(name = "success", type = "json", params = {"root", "employeeWorkExperiences"})
    })
    public String experience() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeWorkExperience.setEmployeeinfoBase(employeeinfoBase);
        employeeWorkExperience.setDiffMon(DateUtil.getMonthsOfAge(employeeWorkExperience.getBeginDate(), employeeWorkExperience.getEndDate()));
        employeeService.saveEmployeeExperience(employeeWorkExperience);

        List<EmployeeWorkExperience> experiences = employeeService.getWorkExperienceList(employeeinfoBase, null, null);
        employeeWorkExperiences = new ArrayList<EmployeeWorkExperience>();
        for (EmployeeWorkExperience experience : experiences) {
            experience.setBeginDateStr(DateUtil.getStrByDate(experience.getBeginDate(), "yyyy年MM月"));
            experience.setEndDateStr(DateUtil.getStrByDate(experience.getEndDate(), "yyyy年MM月"));
            employeeWorkExperiences.add(experience);
        }
        return SUCCESS;
    }

    @Action(value = "/employee/exp_list")
    public String experience_list() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeWorkExperience.setEmployeeinfoBase(employeeinfoBase);
        employeeWorkExperience.setDiffMon(DateUtil.getMonthsOfAge(employeeWorkExperience.getBeginDate(), employeeWorkExperience.getEndDate()));
        if (employeeWorkExperience.getId() == null) {
            employeeService.saveEmployeeExperience(employeeWorkExperience);
        } else {
            employeeService.updateEmployeeRelatedEntity(employeeWorkExperience);
        }

        List<EmployeeWorkExperience> experiences = employeeService.getWorkExperienceList(employeeinfoBase, null, null);
        employeeWorkExperiences = new ArrayList<EmployeeWorkExperience>();
        for (EmployeeWorkExperience experience : experiences) {
            experience.setBeginDateStr(DateUtil.getStrByDate(experience.getBeginDate(), "yyyy年MM月"));
            experience.setEndDateStr(DateUtil.getStrByDate(experience.getEndDate(), "yyyy年MM月"));
            employeeWorkExperiences.add(experience);
        }
        return "exp_list";
    }

    @Action(value = "/employee/staff_family", results = {
            @Result(name = "success", type = "json")
    })
    public String family() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoFamily.setEmployeeinfoBase(employeeinfoBase);
        if (employeeinfoFamily.getId() == null) {
            employeeService.saveEmployeeFamily(employeeinfoFamily);
        } else {
            employeeService.updateEmployeeRelatedEntity(employeeinfoFamily);
        }

        return SUCCESS;
    }

    @Action(value = "/employee/family_list")
    public String family_list() throws Exception {
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        employeeinfoFamily.setEmployeeinfoBase(employeeinfoBase);
        if (employeeinfoFamily.getId() == null) {
            employeeService.saveEmployeeFamily(employeeinfoFamily);
        } else {
            employeeService.updateEmployeeRelatedEntity(employeeinfoFamily);
        }

        employeeinfoFamilies = employeeService.getEmployeeFamilyList(employeeinfoBase, null, null);

        return "family_list";
    }

    @Action(value = "/employee/staff_over", results = {
            @Result(name = "success", type = "json", params = {"root", "pojo"})
    })
    public String over() throws Exception {
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        String totalTime = DateUtil.getDiffDate(start, end);
        employeeinfoBase = (EmployeeinfoBase) ServletActionContext.getRequest().getSession().getAttribute("baseinfo");
        String userName = employeeinfoBase.getName();
        pojo = new StaffSearchPojo(userName, totalTime);
        //清空session
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");
        ServletActionContext.getRequest().getSession().removeAttribute("baseinfo");
        return SUCCESS;
    }

    @Action(value = "/employee/staff_delete")
    public String delete() throws Exception {
        if (StringUtils.isBlank(empIds)) {
            return execute();
        }
        employeeService.removeEmployee(empIds, 1);
        return execute();
    }

    //初始化考勤数据库员工表
    @Action(value = "/public/member-init", results = {@Result(name = "success", location = "member_index.jsp")})
    public String initMemberDB() throws Exception {
        employeeService.initMemberDB();

        return "member-init";
    }


    public List<Organization> getChildOrgs() {
        return childOrgs;
    }

    public void setChildOrgs(List<Organization> childOrgs) {
        this.childOrgs = childOrgs;
    }

    public String getEmployeeNo() {
        return employeeNo;
    }

    public void setEmployeeNo(String employeeNo) {
        this.employeeNo = employeeNo;
    }

    public Organization getOrganzaztion() {
        return organization;
    }

    public void setOrganzaztion(Organization organzaztion) {
        this.organization = organzaztion;
    }

    public List<Organization> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(List<Organization> organizations) {
        this.organizations = organizations;
    }

    public EmployeeinfoWork getEmployeeinfoWork() {
        return employeeinfoWork;
    }

    public void setEmployeeinfoWork(EmployeeinfoWork employeeinfoWork) {
        this.employeeinfoWork = employeeinfoWork;
    }

    public LimitedList<EmployeeinfoWork> getEmployeeinfoWorks() {
        return employeeinfoWorks;
    }

    public void setEmployeeinfoWorks(LimitedList<EmployeeinfoWork> employeeinfoWorks) {
        this.employeeinfoWorks = employeeinfoWorks;
    }

    public EmployeeinfoBase getEmployeeinfoBase() {
        return employeeinfoBase;
    }

    public void setEmployeeinfoBase(EmployeeinfoBase employeeinfoBase) {
        this.employeeinfoBase = employeeinfoBase;
    }

    public String getEmpIds() {
        return empIds;
    }

    public void setEmpIds(String empIds) {
        this.empIds = empIds;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public EmployeeinfoTrain getEmployeeinfoTrain() {
        return employeeinfoTrain;
    }

    public void setEmployeeinfoTrain(EmployeeinfoTrain employeeinfoTrain) {
        this.employeeinfoTrain = employeeinfoTrain;
    }

    public EmployeeinfoEducation getEmployeeinfoEducation() {
        return employeeinfoEducation;
    }

    public void setEmployeeinfoEducation(EmployeeinfoEducation employeeinfoEducation) {
        this.employeeinfoEducation = employeeinfoEducation;
    }

    public EmployeeWorkExperience getEmployeeWorkExperience() {
        return employeeWorkExperience;
    }

    public void setEmployeeWorkExperience(EmployeeWorkExperience employeeWorkExperience) {
        this.employeeWorkExperience = employeeWorkExperience;
    }

    public EmployeeinfoFamily getEmployeeinfoFamily() {
        return employeeinfoFamily;
    }

    public void setEmployeeinfoFamily(EmployeeinfoFamily employeeinfoFamily) {
        this.employeeinfoFamily = employeeinfoFamily;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<EmployeeinfoEducation> getEmployeeinfoEducationList() {
        return employeeinfoEducationList;
    }

    public void setEmployeeinfoEducationList(List<EmployeeinfoEducation> employeeinfoEducationList) {
        this.employeeinfoEducationList = employeeinfoEducationList;
    }

    public List<EmployeeinfoTrain> getEmployeeinfoTrains() {
        return employeeinfoTrains;
    }

    public void setEmployeeinfoTrains(List<EmployeeinfoTrain> employeeinfoTrains) {
        this.employeeinfoTrains = employeeinfoTrains;
    }

    public List<EmployeeWorkExperience> getEmployeeWorkExperiences() {
        return employeeWorkExperiences;
    }

    public void setEmployeeWorkExperiences(List<EmployeeWorkExperience> employeeWorkExperiences) {
        this.employeeWorkExperiences = employeeWorkExperiences;
    }

    public List<EmployeeinfoFamily> getEmployeeinfoFamilies() {
        return employeeinfoFamilies;
    }

    public void setEmployeeinfoFamilies(List<EmployeeinfoFamily> employeeinfoFamilies) {
        this.employeeinfoFamilies = employeeinfoFamilies;
    }
    
    public void setAttendances(LimitedList<Attendance> attendances) {
		this.attendances = attendances;
	}
    
    public LimitedList<Attendance> getAttendances() {
		return attendances;
	}

    public StaffSearchPojo getSearch() {
        return search;
    }

    public void setSearch(StaffSearchPojo search) {
        this.search = search;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public Long getDutyId() {
        return dutyId;
    }

    public void setDutyId(Long dutyId) {
        this.dutyId = dutyId;
    }

    public List<Duty> getDuties() {
        return duties;
    }

    public void setDuties(List<Duty> duties) {
        this.duties = duties;
    }

    public List<Grade> getGrades() {
        return grades;
    }

    public void setGrades(List<Grade> grades) {
        this.grades = grades;
    }

    public List<Grade> getGradeLvs() {
        return gradeLvs;
    }

    public void setGradeLvs(List<Grade> gradeLvs) {
        this.gradeLvs = gradeLvs;
    }

    public Long getGradeId() {
        return gradeId;
    }

    public void setGradeId(Long gradeId) {
        this.gradeId = gradeId;
    }

    public Long getGradeLvId() {
        return gradeLvId;
    }

    public void setGradeLvId(Long gradeLvId) {
        this.gradeLvId = gradeLvId;
    }

    public StaffSearchPojo getPojo() {
        return pojo;
    }

    public void setPojo(StaffSearchPojo pojo) {
        this.pojo = pojo;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Long getEduId() {
        return eduId;
    }

    public void setEduId(Long eduId) {
        this.eduId = eduId;
    }

    public Long getOrgParentId() {
        return orgParentId;
    }

    public void setOrgParentId(Long orgParentId) {
        this.orgParentId = orgParentId;
    }

    public boolean isTopOrg() {
        return topOrg;
    }

    public void setTopOrg(boolean topOrg) {
        this.topOrg = topOrg;
    }

    public boolean isExportEmployee() {
        return exportEmployee;
    }

    public void setExportEmployee(boolean exportEmployee) {
        this.exportEmployee = exportEmployee;
    }

    @Override
    protected String getTemplate() {
        return "employee_report.xls";
    }

    @Override
    protected String fileName() {
        return "employee_report_"+System.currentTimeMillis();
    }
    
    public int getStartYear() {
		return startYear;
	}
    
    public void setStartYear(int startYear) {
		this.startYear = startYear;
	}
    
    public int getEndYear() {
		return endYear;
	}
    
    public void setEndYear(int endYear) {
		this.endYear = endYear;
	}
    
    public List<ExamPeriod> getExamPeriods() {
		return examPeriods;
	}
    
    public void setExamPeriods(List<ExamPeriod> examPeriods) {
		this.examPeriods = examPeriods;
	}
    
    public LimitedList<ExamStatisticsPojo> getExamQuans() {
		return examQuans;
	}
    
    public void setExamQuans(LimitedList<ExamStatisticsPojo> examQuans) {
		this.examQuans = examQuans;
	}
    
    public LimitedList<ExamStatisticsPojo> getExamQuals() {
		return examQuals;
	}
    
    public void setExamQuals(LimitedList<ExamStatisticsPojo> examQuals) {
		this.examQuals = examQuals;
	}
    
    public LimitedList<ExamStatisticsPojo> getExamStats() {
		return examStats;
	}
    
    public void setExamStats(LimitedList<ExamStatisticsPojo> examStats) {
		this.examStats = examStats;
	}
    
    public LimitedList<Transaction> getOrgTrans() {
		return orgTrans;
	}
    
    public void setOrgTrans(LimitedList<Transaction> orgTrans) {
		this.orgTrans = orgTrans;
	}
    
    public LimitedList<Transaction> getProTrans() {
		return proTrans;
	}
    
    public void setProTrans(LimitedList<Transaction> proTrans) {
		this.proTrans = proTrans;
	}
    
    public LimitedList<Transaction> getDemTrans() {
		return demTrans;
	}
    
    public void setDemTrans(LimitedList<Transaction> demTrans) {
		this.demTrans = demTrans;
	}
    
}
